package com.lagou.jdbc03;

import com.lagou.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author wsl
 * @Date 2021/8/19 22:42
 * @Project_Name mysql
 */
public class TestPS {

    public static void main(String[] args) throws SQLException {

        //1.注册驱动
        Connection con = JDBCUtils.getConnection();

        //2.获取statement对象
        Statement statement = con.createStatement();

        //3.插入两条数据
        statement.executeUpdate("insert into jdbc_user values(null,'张三','123','1992/12/26')");
        statement.executeUpdate("insert into jdbc_user values(null,'李四','123','1992/12/26')");

        System.out.println("-----------------------------------------");
        //4.获取预处理对象
        PreparedStatement ps = con.prepareStatement("insert into jdbc_user values(?,?,?,?)");

        //5.第一条数据，设置占位符
        ps.setString(1,null);
        ps.setString(2,"长海");
        ps.setString(3,"qwer");
        ps.setString(4,"1990/1/10");

        //6.执行插入
        ps.executeUpdate();

        //7.第二条数据 ,设置占位符
        ps.setString(1,null);
        ps.setString(2,"小斌");
        ps.setString(3,"1122");
        ps.setString(4,"1990/1/10");

        //8.执行插入
        ps.executeUpdate();

        //9.释放资源
        ps.close();
        statement.close();
        con.close();

    }
}
